package com.hnqcgczy.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class IDbImpl implements IDb {
    private String URL = "jdbc:mysql://localhost:3306/dujiaoshou?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
    private String USERNAME = "root";
    private String PASSWORD = "123456";

    public IDbImpl() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Connection getConnByMysql() throws SQLException {
        Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        return connection;
    }

    @Override
    public Connection getConnByOracle() throws SQLException {
        return null;
    }

    public static void main(String[] args) {
        IDbImpl myconn = new IDbImpl();
        try {
            Connection connByMysql = myconn.getConnByMysql();
            System.out.println(connByMysql.isClosed());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
